/**
 * *
 *
 * @author LWG
 * @date 2022/7/19 21：06
 * @since 1.0.0
 */
import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    shareArray: JSON.parse(localStorage.getItem('SHAREARRAY')) || [],
    userinfo: JSON.parse(localStorage.getItem('USERINFO')) || {},
    changeIcon: JSON.parse(localStorage.getItem('CHANGEICON')) ? JSON.parse(localStorage.getItem('CHANGEICON')) :
        {
          likeIcon: 'like-o',
          collectionIcon: 'star-o',
          followIcon: ''
        },
    activeName: JSON.parse(localStorage.getItem('ACTIVENAME')) ? JSON.parse(localStorage.getItem('ACTIVENAME')) : 1001,
    helpActive: JSON.parse(localStorage.getItem('HELPACTIVE')) ? JSON.parse(localStorage.getItem('HELPACTIVE')) : 1001,
    helpArray: JSON.parse(localStorage.getItem('HELPARRAY')) || [],
    helpSC: JSON.parse(localStorage.getItem('HELPSC')) ? JSON.parse(localStorage.getItem('HELPSC')) : "本校区",
  },
  getters: {
    getShare(state){
      return state.shareArray
    },
    getUserInfo(state){
      return state.userinfo
    },
    getActiveName(state){
      return state.activeName
    },
    getChangeIcon(state){
      return state.changeIcon
    },
    getHelpActive(){
      return state.helpActive
    },
    getHelpArray(){
      return this.state.helpArray
    },
    getHelpSC(){
      return this.state.helpSC
    }
  },

  mutations: {
    updateShareArray(state,shareArray){
      state.shareArray = shareArray
      localStorage.setItem('SHAREARRAY',JSON.stringify(shareArray))
      console.log('qqqqqqqqqqq',state.shareArray)
    },
    updateUserInfo(state,userinfo){
      state.userinfo = userinfo
      localStorage.setItem('USERINFO',JSON.stringify(userinfo))
      console.log('userinfo:',state.userinfo)
    },
    updateActiveName(state,activeName){
      state.activeName = activeName
      localStorage.setItem('ACTIVENAME',JSON.stringify(activeName))
      console.log('activeName:',state.activeName)
    },
    updateChangeIcon(state,changeIcon){
      state.changeIcon = changeIcon
      localStorage.setItem('CHANGEICON',JSON.stringify(changeIcon))
      console.log('changeIcon:',state.changeIcon)
    },
    updateHelpActive(state,helpActive){
      state.helpActive = helpActive
      localStorage.setItem("HELPACTIVE",JSON.stringify(helpActive))
      console.log('helpActive', state.helpActive)
    },
    updateHelpArray(state,helpArray){
      state.helpArray = helpArray
      localStorage.setItem('HELPARRAY',JSON.stringify(helpArray))
      console.log('helpArray',state.helpArray)
    },
    updateHelpSC(state,helpSC){
      state.helpSC = helpSC
      localStorage.setItem('HELPSC',JSON.stringify(helpSC))
      console.log('helpSC',state.helpSC)
    }
  },

  actions: {
    asyncUpdateShareArray(context,shareArray){
      context.commit('updateShareArray',shareArray)
    },
    asyncUpdateUserInfo(context,userinfo){
      context.commit('updateUserInfo',userinfo)
    },
    asyncUpdateActiveName(context,activeName){
      context.commit('updateActiveName',activeName)
    },
    asyncUpdateChangeIcon(context,changeIcon){
      context.commit('updateChangeIcon',changeIcon)
    },
    asyncUpdateHelpActive(context,helpActive){
      context.commit('updateHelpActive',helpActive)
    },
    asyncUpdateHelpArray(context,helpArray){
      context.commit('updateHelpArray',helpArray)
    },
    asyncUpdateHelpSC(context,helpSC){
      context.commit('updateHelpSC',helpSC)
    }
  },
  modules: {
  }
})

